<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-02-01 10:14:53
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2024-02-27 13:57:52
 * @FilePath: \ZHGD-Vue2\src\views\bitumenMixingStation\statisticalReport\productionStatistics.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 产量统计报表 -->
<template>
    <div class="productionSummary">
        <el-row :gutter="20">
            <el-col :span="show ? rowObj.T1 : rowObj.F1" :xs="show ? rowObj.T2 : rowObj.F2">
                <workSiteLeft ref="workSiteLeft" :show="show" @showLeft="showLeft" @queryVal="queryVal" />
            </el-col>
            <el-col :span="show ? rowObj.T3 : rowObj.F3" :xs="show ? rowObj.T4 : rowObj.F4">
                <div class="container-body">
                    <el-form :inline="true" :model="queryParams" size="small" class="mySearch">
                        <el-button style="margin: 3px 8px 0 0;" size="mini"
                            :icon="show ? 'el-icon-s-fold' : 'el-icon-s-unfold'" circle @click="showLeft(show)"></el-button>
                        <el-form-item label="拌合楼">
                            <el-select style="width: 160px" v-model="queryParams.stationCode" clearable size="mini"
                                placeholder="请选择拌合楼">
                                <el-option v-for="item in cementListData" :key="item.id" :label="item.name"
                                    :value="item.code">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="配方编号">
                            <el-input style="width: 140px" v-model="queryParams.matchCode" placeholder="配方编号"
                                clearable></el-input>
                        </el-form-item>
                        <el-form-item label="项目名称">
                            <el-input style="width: 140px" v-model="queryParams.projectName" placeholder="项目名称"
                                clearable></el-input>
                        </el-form-item>
                        <el-form-item label="选择时间">
                            <el-select filterable v-model="timeType" style="width: 90px; margin-right: 8px"
                                :popper-append-to-body="false">
                                <el-option label="日报" value="day"></el-option>
                                <el-option label="月报" value="month"></el-option>
                                <el-option label="年报" value="year"></el-option>
                                <el-option label="自定义" value="other"></el-option>
                            </el-select>
                            <el-date-picker style="width: 130px" v-if="'day' == timeType" v-model="queryParams.day"
                                value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
                                placeholder="选择日期"></el-date-picker>
                            <el-date-picker style="width: 130px" v-if="'month' == timeType" v-model="queryParams.month"
                                value-format="yyyy-MM" format="yyyy-MM" type="month" placeholder="选择月份"></el-date-picker>
                            <el-date-picker style="width: 130px" v-if="'year' == timeType" v-model="queryParams.year"
                                value-format="yyyy" format="yyyy" type="year" placeholder="选择年份"></el-date-picker>
                            <deatetime v-if="'other' == timeType" ref="deatetime" v-model="queryParams.timeRange">
                            </deatetime>
                        </el-form-item>
                        <el-form-item>
                            <el-button icon="el-icon-search" type="primary" @click="handleQuery">查询</el-button>
                        </el-form-item>
                        <div style="float: right">
                            <el-form-item>
                                <el-button type="warning" plain icon="el-icon-download" @click="onExport">导出</el-button>
                            </el-form-item>
                        </div>
                    </el-form>
                    <el-table :data="dataList" show-overflow-tooltip="true" border size="mini" highlight-current-row
                        stripe>
                        <el-table-column align="center" prop="stationName" label="拌和楼" width="300px"></el-table-column>
                        <el-table-column align="center" prop="matchType" label="级配类型"></el-table-column>
                        <el-table-column align="center" prop="matchName" label="配方名称"></el-table-column>
                        <el-table-column align="center" prop="matchCode" label="配方编号"></el-table-column>
                        <el-table-column align="center" prop="pavingLevelLabel" label="摊铺层级"></el-table-column>
                        <el-table-column align="center" prop="projectName" label="项目名称" width="300px"></el-table-column>
                        <el-table-column align="center" prop="batch" label="生产批次"></el-table-column>
                        <el-table-column align="center" prop="weight" label="生产重量(吨)"></el-table-column>
                        <el-table-column align="center" prop="avgAsphaltAggregateRatio" label="平均油石比"></el-table-column>
                        <el-table-column align="center" prop="theoAsphaltAggregateRatio" label="设计油石比"></el-table-column>
                    </el-table>
                    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                        :limit.sync="queryParams.pageSize" @pagination="getList" />
                </div>
            </el-col>
        </el-row>
    </div>
</template>
  
<script>
import {
    sysStationList,
    getLastData,
    asphaltOutputSummary
} from "@/api/bitumenMixingStation/statisticalReport/productionStatistics.js";
import deatetime from "@/components/Datetime";
import workSiteLeft from "@/views/components/workSiteLeft";

export default {
    name: 'productionStatistics', // 产量统计汇总
    components: { deatetime, workSiteLeft },
    filters: {

    },
    data() {
        return {
            show: true,
            rowObj: {
                T1: 3,
                T2: 24,
                T3: 21,
                T4: 24,
                F1: 0,
                F2: 0,
                F3: 24,
                F4: 24,
            },
            timeType: "all",
            cementListData: [],
            quListData: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            dataList: [],
            loading: false,
        };
    },
    mounted() {
        this.getCementList();
        this.getLastDayApi()
        // this.getQuList()

    },
    methods: {
        showLeft(show) {
            this.show = !show;
        },
        queryVal(val) {
            this.queryParams.id = val.id;
            this.handleQuery();
        },
        // 查询拌合楼下拉列表
        getCementList() {
            sysStationList().then((res) => {
                this.cementListData = res.data || [];
            });
        },

        getList() {
            this.loading = true;
            asphaltOutputSummary(this.queryParams).then((response) => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        handleQuery() {
            this.queryParams = this.getSearchParams();
            this.queryParams.pageNum = 1;
            this.getList();
        },
        getSearchParams() {
            const params = {};
            for (const key in this.queryParams) {
                if (key === "time") {
                    const time = this.queryParams[key];
                    if (time && time.length === 2) {
                        params.startTime = time[0];
                        params.endTime = time[1];
                    }
                } else {
                    params[key] = this.queryParams[key];
                }
            }
            return params;
        },
        // 查询时间
        getLastDayApi() {
            getLastData().then((res) => {
                if (!!res.data) {
                    this.timeType = 'day';
                    this.queryParams['year'] = res.data.substring(0, 4);
                    this.queryParams['month'] = res.data.substring(0, 7);
                    this.queryParams['day'] = res.data;
                }
                this.getList();
            });
        },
        /*** 数据导出*/
        onExport() {
            this.$message.info('正在开发中~~~~')
            // api
            //     .exportExcel(this.searchParams)
            //     .then((res) => {
            //         const blob = new Blob([res]);
            //         var href = window.URL.createObjectURL(blob);
            //         var downloadElement = document.createElement('a');
            //         downloadElement.href = href;
            //         downloadElement.download = decodeURIComponent('产量统计汇总.xls');
            //         document.body.appendChild(downloadElement);
            //         downloadElement.click();
            //         document.body.removeChild(downloadElement);
            //         window.URL.revokeObjectURL(href);
            //     })
            //     .catch(() => { });
        }
    }
};
</script>
  
<style scoped lang="scss" >
.productionSummary {
    padding: 16px;
}
</style>
  